package com.member.test.controller;

import com.api.openfeign.client.UserClient;
import com.api.openfeign.dto.UserDto;
import com.repeat.member.MemberApplication;
import com.repeat.member.config.DirectConfig;
import com.repeat.member.config.FanoutConfig;
import com.repeat.member.config.TopicConfig;
import com.repeat.member.mq.consump.UserPointsConsump;
import com.repeat.member.mq.produc.UserPointsProduct;
import com.repeat.member.mq.produc.UserProduct;
import com.shop.common.constant.RabbitFinalConstant;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@SpringBootTest(classes = MemberApplication.class)
public class MessageController {
    @Test
    public void test() {
        System.out.println("12323test");
        log.info("12323test");
    }

    @Autowired
    private RabbitTemplate rabbitTemplate;
    //普通消息发送
    @Test
    public void ordinary_messages() {
        rabbitTemplate.convertAndSend( "user_queue","普通消息发送");
        System.out.println("普通消息发送");
    }
    //发送工作模式
    @Test
    public void work_messages() throws InterruptedException {
         for (int i=0;i<10;i++){
             String queueName = "user_queue";
             rabbitTemplate.convertAndSend( queueName,"工作模式消息发送");
             Thread.sleep(20);
        }
        System.out.println("工作消息发送");
    }
    //订阅模式 1.广播
    @Test
    public void subscribeFanout() {
        rabbitTemplate.convertAndSend(FanoutConfig.FANOUT_EXCHANGE,"","Fanout广播消息发送");
        System.out.println("订阅Fanout广播");
    }
    //订阅模式 2.Direct
    @Test
    public void subscribeDirect() {
        rabbitTemplate.convertAndSend(DirectConfig.DIRECT_EXCHANGE,DirectConfig.DIRECT_ROUTING_KEY_WHITE,"红色中的白色");
        System.out.println("订阅Direct");
    }
    //订阅模式 3.主题
    @Test
    public void subscribeTopic() {
         String routing = "lazy.weather.weather.new";
         String message = "主题为新闻";
         rabbitTemplate.convertAndSend(TopicConfig.TOPIC_EXCHANGE,routing,message);
        System.out.println("订阅主题");
    }
    @Autowired
    private UserPointsProduct userPointsProduct;
    @Autowired
    private UserClient userClient;

    @Autowired
    private UserPointsConsump userPointsConsump;

    @Test
    public void singPoints() {
//        Map<String,Object> map = new HashMap<>();
//        map.put("user_id",2);
//        map.put("points",200);
//
//       userPointsProduct.SendPointsMsg(RabbitFinalConstant.POINTS_EXCHANGE,RabbitFinalConstant.SING_ROUTING_KEY,map);

        //userPointsConsump.sign();
    }
}
